AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )

function ENT:Initialize()
	self.Entity:SetModel("models/items/grenadeammo.mdl")
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:DrawShadow( false )
	
	--self.Entity:SetCollisionGroup( COLLISION_GROUP_WEAPON )
	
	local phys = self.Entity:GetPhysicsObject()
	
	if (phys:IsValid()) then
		phys:Wake()
	end
	
	self.DetonateTime = CurTime() + 3
end

function ENT:Think()
	if CurTime() > self.DetonateTime then
		self:Detonate()
	end
end

function ENT:Detonate()
	if self.Detonated then return end
	self.Detonated = true
	local expl = ents.Create ("env_explosion")
	expl:SetKeyValue ("iMagnitude", 50)
	expl:SetKeyValue ("spawnflags", 144)
	expl:Spawn ()
	expl:SetPos (self.Entity:GetPos())
	expl:SetOwner (self.Entity:GetOwner())
	expl:Fire ("Explode", "", 0.01)
	expl:Fire ("Kill", "", 0.1)
	if self.Entity.trail then
		printd ("got trail")
		self.Entity.trail:SetParent ()
		self.Entity.trail:Fire ("Kill", 0.5)
	end
	self.Entity:Fire ("Kill", 0.1)
end

function ENT:PhysicsCollide()
	self:Detonate()
end

function ENT:SetTrail (trail, trailsprite)
	
end
